package com.hexacta.hrs.test.data;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.vectrics.employee.Employee;

import com.hexacta.hrs.timeoff.Status;
import com.hexacta.hrs.timeoff.TimeOff;
import com.hexacta.hrs.timeoff.TimeOffStatusDetail;
import com.hexacta.hrs.timeoff.TimeOffType;

/**
 * Test data dependency creator for the TimeOff class.
 * 
 * @author tpollak
 */
public class TimeOffTestDataDependencyCreator extends AbstractTestDataDependencyCreator {

    public TimeOffTestDataDependencyCreator(List<TestDataDependencyCreator> dependencies) {
        super(dependencies);
    }

    public void createDependentTestData(Map<String, Object> context) {
        TimeOff timeOff1 = this.createTimeOff(context, EmployeeTestDataDependencyCreator.EMPLOYEE_1);
        TimeOff timeOff2 = this.createTimeOff(context, EmployeeTestDataDependencyCreator.EMPLOYEE_2);
        TimeOff timeOff3 = this.createTimeOff(context, EmployeeTestDataDependencyCreator.EMPLOYEE_3);
        TimeOff timeOff4 = this.createTimeOff(context, EmployeeTestDataDependencyCreator.EMPLOYEE_4);
        TimeOff timeOff5 = this.createTimeOff(context, EmployeeTestDataDependencyCreator.EMPLOYEE_5);

        timeOff1 = this.insertDomainObject(timeOff1);
        timeOff2 = this.insertDomainObject(timeOff2);
        timeOff3 = this.insertDomainObject(timeOff3);
        timeOff4 = this.insertDomainObject(timeOff4);
        timeOff5 = this.insertDomainObject(timeOff5);
    }

    @Override
    public Set<Scenario> getApplicableScenarios() {
        return EnumSet.of(Scenario.DEVELOPMENT);
    }

    private TimeOff createTimeOff(Map<String, Object> context, String employeeToken) {
        Employee employee = (Employee) this.loadObjectFromContext(context, employeeToken);
        TimeOff timeOff = new TimeOff();
        timeOff.setEmployee(employee);
        // timeOff.setDateFrom(DataUtils.createCurrentDate());
        // timeOff.setDateTo(DataUtils.createCurrentDate());
        timeOff.changeDates(this.getDataUtils().createCurrentDate(), this.getDataUtils().createCurrentDate());
        timeOff.setTimeOffType(TimeOffType.ENFERMEDAD);
        TimeOffStatusDetail status = new TimeOffStatusDetail();
        status.setApprovedBy(employee);
        status.setEditedBy(employee.getPerson());
        status.setStatus(Status.REQUESTED);
        status.setTransitionDate(this.getDataUtils().createCurrentDate());
        timeOff.addNewStatus(status);
        return timeOff;
    }
}
